package com.baijiarui.myself;

import com.fc.test.mapper.auto.ForeCompanyMapper;
import com.fc.test.mapper.auto.ForeNewsMapper;
import com.fc.test.mapper.auto.ForeStudentMapper;
import com.fc.test.mapper.auto.TsysUserMapper;
import com.fc.test.model.auto.ForeStudent;
import com.fc.test.model.auto.TsysUser;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CommonController {
    @Autowired
    ForeNewsMapper foreNewsMapper;
    @Autowired
    TsysUserMapper tsysUserMapper;
    @Autowired
    ForeStudentMapper foreStudentMapper;
    @Autowired
    ForeCompanyMapper foreCompanyMapper;




    @RequestMapping("/common/newsList")
    public Object newsList(){
        return foreNewsMapper.selectByExample(null);
    }
    @RequestMapping("/common/newsDetails")
    public Object newsDetails(String id){
        return foreNewsMapper.selectByPrimaryKey(id);
    }

    @RequestMapping("/common/cancellation")
    public Object cancellation(){
        TsysUser user = (TsysUser) SecurityUtils.getSubject().getPrincipal();
        String userId=user.getId();
        Integer i1=foreCompanyMapper.deleteByPrimaryKey(userId);
        Integer i2=foreStudentMapper.deleteByPrimaryKey(userId);
        Integer i3=tsysUserMapper.deleteByPrimaryKey(userId);
        SecurityUtils.getSubject().logout();
        return i1+i2+i3==2?"success":"fail";
    }



}
